#!/usr/bin/env python2

import xaut
import os
import sys
import subprocess


AOS_DISP = os.getenv('DISPLAY')
if AOS_DISP==None:
    print "DISP=NULL,set it."
    AOS_DISP=":0.0"
    os.environ['DISPLAY'] = AOS_DISP

print "create 2 process of APP in " + os.getenv('DISPLAY')

print "APP1 window creating"
#os.system("xinit /usr/share/uosbrowser/uosbrowser /home/user/src/Helpzd/xaut-v5/python/aos_main2.html -- :2.0 vt2 >/tmp/aos.err 2>&1 & ")
os.system("/usr/share/uosbrowser/uosbrowser /home/user/src/Helpzd/xaut-v5/python/aos_main2.html >/tmp/aos.err 2>&1 & ")
#subprocess.call("/usr/share/uosbrowser/uosbrowser aos_main2.html".split(), shell=False)

#p = subprocess.Popen('xinit /usr/share/uosbrowser/uosbrowser /home/user/src/Helpzd/xaut-v5/python/aos_main2.html -- :2.0 vt2 &', shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
#p = subprocess.Popen('/usr/share/uosbrowser/uosbrowser aos_main2.html', shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
#p = subprocess.Popen('xprop -root', shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
#for line in p.stdout.readlines():
#    print line,
#retval = p.wait()
#print "APP1 exit.[%d]" % (retval)

raw_input("Press Enter to fullscree APP1...")

kbd = xaut.keyboard()
#kbd.type("echo password")

success = kbd.click(95) #Sends the F11 key
if(success):
    print("he keycode was sent")
else:
    print("an error when sending keycode")


raw_input("Press Enter to create APP2...")
os.system("gnome-system-monitor >/tmp/APP2.log 2>&1 &")


raw_input("Press Enter to resize APP2 to fix AREA...")

raw_input("Press Enter to move APP2 to assigned AREA...")
#os.system("wmctrl -r aaa -e 235,-20,844,703")

